package org.admanager.piadladmapping.plugin.diagram.part;

import org.admanager.piadladmanagement.plugin.piadladmanagement.MappingRoot;
import org.admanager.piadladmanagement.plugin.piadladmanagement.PiadladmanagementPackage;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.Architecture2EditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.ArchitectureArchitectureCompartment2EditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.ArchitectureArchitectureCompartmentEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.ArchitectureEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.ArchitectureName2EditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.ArchitectureNameEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.CBAPatternCBAPatternCompartmentEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.CBAPatternEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.CBAPatternNameEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.ComponentComponentCompartmentEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.ComponentEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.ComponentMappingEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.ComponentNameEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.ComponentPortMappingEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.ConnectorConnectorCompartmentEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.ConnectorEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.ConnectorMappingEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.ConnectorNameEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.ConnectorRoleMappingEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.MappingRootEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.PComponent2EditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.PComponentEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.PComponentName2EditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.PComponentNameEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.PComponentPComponentCompartment2EditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.PComponentPComponentCompartmentEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.PComponentPort2EditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.PComponentPortEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.PConnector2EditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.PConnectorEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.PConnectorName2EditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.PConnectorNameEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.PConnectorPConnectorCompartment2EditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.PConnectorPConnectorCompartmentEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.PConnectorRole2EditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.PConnectorRoleEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.PConstraintEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.PConstraintNameEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.PMultiplicityEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.PRoleEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.PRoleNameEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.PRolePRoleCompartmentEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.Port2EditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.PortEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.RelayEditPart;
import org.admanager.piadladmapping.plugin.diagram.edit.parts.UnificationEditPart;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.View;

/**
 * This registry is used to determine which type of visual object should be
 * created for the corresponding Diagram, Node, ChildNode or Link represented
 * by a domain model object.
 * 
 * @generated
 */
public class PiADLADManagementMetamodelVisualIDRegistry {

	/**
	 * @generated
	 */
	private static final String DEBUG_KEY = "org.admanager.piadladmapping.plugin.diagram/debug/visualID"; //$NON-NLS-1$

	/**
	 * @generated
	 */
	public static int getVisualID(View view) {
		if (view instanceof Diagram) {
			if (MappingRootEditPart.MODEL_ID.equals(view.getType())) {
				return MappingRootEditPart.VISUAL_ID;
			} else {
				return -1;
			}
		}
		return org.admanager.piadladmapping.plugin.diagram.part.PiADLADManagementMetamodelVisualIDRegistry
				.getVisualID(view.getType());
	}

	/**
	 * @generated
	 */
	public static String getModelID(View view) {
		View diagram = view.getDiagram();
		while (view != diagram) {
			EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
			if (annotation != null) {
				return (String) annotation.getDetails().get("modelID"); //$NON-NLS-1$
			}
			view = (View) view.eContainer();
		}
		return diagram != null ? diagram.getType() : null;
	}

	/**
	 * @generated
	 */
	public static int getVisualID(String type) {
		try {
			return Integer.parseInt(type);
		} catch (NumberFormatException e) {
			if (Boolean.TRUE.toString().equalsIgnoreCase(
					Platform.getDebugOption(DEBUG_KEY))) {
				PiADLADManagementMetamodelDiagramEditorPlugin.getInstance()
						.logError(
								"Unable to parse view type as a visualID number: "
										+ type);
			}
		}
		return -1;
	}

	/**
	 * @generated
	 */
	public static String getType(int visualID) {
		return Integer.toString(visualID);
	}

	/**
	 * @generated
	 */
	public static int getDiagramVisualID(EObject domainElement) {
		if (domainElement == null) {
			return -1;
		}
		if (PiadladmanagementPackage.eINSTANCE.getMappingRoot().isSuperTypeOf(
				domainElement.eClass())
				&& isDiagram((MappingRoot) domainElement)) {
			return MappingRootEditPart.VISUAL_ID;
		}
		return -1;
	}

	/**
	 * @generated
	 */
	public static int getNodeVisualID(View containerView, EObject domainElement) {
		if (domainElement == null) {
			return -1;
		}
		String containerModelID = org.admanager.piadladmapping.plugin.diagram.part.PiADLADManagementMetamodelVisualIDRegistry
				.getModelID(containerView);
		if (!MappingRootEditPart.MODEL_ID.equals(containerModelID)
				&& !"piadlpat".equals(containerModelID) && !"piadl".equals(containerModelID)) { //$NON-NLS-1$ //$NON-NLS-2$
			return -1;
		}
		int containerVisualID;
		if (MappingRootEditPart.MODEL_ID.equals(containerModelID)) {
			containerVisualID = org.admanager.piadladmapping.plugin.diagram.part.PiADLADManagementMetamodelVisualIDRegistry
					.getVisualID(containerView);
		} else {
			if (containerView instanceof Diagram) {
				containerVisualID = MappingRootEditPart.VISUAL_ID;
			} else {
				return -1;
			}
		}
		switch (containerVisualID) {
		case MappingRootEditPart.VISUAL_ID:
			if (PiadladmanagementPackage.eINSTANCE.getComponentPortMapping()
					.isSuperTypeOf(domainElement.eClass())) {
				return ComponentPortMappingEditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getConnectorRoleMapping()
					.isSuperTypeOf(domainElement.eClass())) {
				return ConnectorRoleMappingEditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getConnectorMapping()
					.isSuperTypeOf(domainElement.eClass())) {
				return ConnectorMappingEditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getComponentMapping()
					.isSuperTypeOf(domainElement.eClass())) {
				return ComponentMappingEditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getCBAPattern()
					.isSuperTypeOf(domainElement.eClass())) {
				return CBAPatternEditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getArchitecture()
					.isSuperTypeOf(domainElement.eClass())) {
				return ArchitectureEditPart.VISUAL_ID;
			}
			break;
		case CBAPatternCBAPatternCompartmentEditPart.VISUAL_ID:
			if (PiadladmanagementPackage.eINSTANCE.getPMultiplicity()
					.isSuperTypeOf(domainElement.eClass())) {
				return PMultiplicityEditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getPRole().isSuperTypeOf(
					domainElement.eClass())) {
				return PRoleEditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getPComponentPort()
					.isSuperTypeOf(domainElement.eClass())) {
				return PComponentPortEditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getPConnectorRole()
					.isSuperTypeOf(domainElement.eClass())) {
				return PConnectorRoleEditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getPComponent()
					.isSuperTypeOf(domainElement.eClass())) {
				return PComponentEditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getPConnector()
					.isSuperTypeOf(domainElement.eClass())) {
				return PConnector2EditPart.VISUAL_ID;
			}
			break;
		case PRolePRoleCompartmentEditPart.VISUAL_ID:
			if (PiadladmanagementPackage.eINSTANCE.getPConstraint()
					.isSuperTypeOf(domainElement.eClass())) {
				return PConstraintEditPart.VISUAL_ID;
			}
			break;
		case PComponentPComponentCompartmentEditPart.VISUAL_ID:
			if (PiadladmanagementPackage.eINSTANCE.getPComponent()
					.isSuperTypeOf(domainElement.eClass())) {
				return PComponent2EditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getPComponentPort()
					.isSuperTypeOf(domainElement.eClass())) {
				return PComponentPort2EditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getPConnector()
					.isSuperTypeOf(domainElement.eClass())) {
				return PConnectorEditPart.VISUAL_ID;
			}
			break;
		case PComponentPComponentCompartment2EditPart.VISUAL_ID:
			if (PiadladmanagementPackage.eINSTANCE.getPComponent()
					.isSuperTypeOf(domainElement.eClass())) {
				return PComponent2EditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getPComponentPort()
					.isSuperTypeOf(domainElement.eClass())) {
				return PComponentPort2EditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getPConnector()
					.isSuperTypeOf(domainElement.eClass())) {
				return PConnectorEditPart.VISUAL_ID;
			}
			break;
		case PConnectorPConnectorCompartmentEditPart.VISUAL_ID:
			if (PiadladmanagementPackage.eINSTANCE.getPConnector()
					.isSuperTypeOf(domainElement.eClass())) {
				return PConnectorEditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getPConnectorRole()
					.isSuperTypeOf(domainElement.eClass())) {
				return PConnectorRole2EditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getPComponent()
					.isSuperTypeOf(domainElement.eClass())) {
				return PComponent2EditPart.VISUAL_ID;
			}
			break;
		case PConnectorPConnectorCompartment2EditPart.VISUAL_ID:
			if (PiadladmanagementPackage.eINSTANCE.getPConnector()
					.isSuperTypeOf(domainElement.eClass())) {
				return PConnectorEditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getPConnectorRole()
					.isSuperTypeOf(domainElement.eClass())) {
				return PConnectorRole2EditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getPComponent()
					.isSuperTypeOf(domainElement.eClass())) {
				return PComponent2EditPart.VISUAL_ID;
			}
			break;
		case ArchitectureArchitectureCompartmentEditPart.VISUAL_ID:
			if (PiadladmanagementPackage.eINSTANCE.getComponent()
					.isSuperTypeOf(domainElement.eClass())) {
				return ComponentEditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getConnector()
					.isSuperTypeOf(domainElement.eClass())) {
				return ConnectorEditPart.VISUAL_ID;
			}
			break;
		case ComponentComponentCompartmentEditPart.VISUAL_ID:
			if (PiadladmanagementPackage.eINSTANCE.getPort().isSuperTypeOf(
					domainElement.eClass())) {
				return PortEditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getArchitecture()
					.isSuperTypeOf(domainElement.eClass())) {
				return Architecture2EditPart.VISUAL_ID;
			}
			break;
		case ArchitectureArchitectureCompartment2EditPart.VISUAL_ID:
			if (PiadladmanagementPackage.eINSTANCE.getComponent()
					.isSuperTypeOf(domainElement.eClass())) {
				return ComponentEditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getConnector()
					.isSuperTypeOf(domainElement.eClass())) {
				return ConnectorEditPart.VISUAL_ID;
			}
			break;
		case ConnectorConnectorCompartmentEditPart.VISUAL_ID:
			if (PiadladmanagementPackage.eINSTANCE.getArchitecture()
					.isSuperTypeOf(domainElement.eClass())) {
				return Architecture2EditPart.VISUAL_ID;
			}
			if (PiadladmanagementPackage.eINSTANCE.getPort().isSuperTypeOf(
					domainElement.eClass())) {
				return Port2EditPart.VISUAL_ID;
			}
			break;
		}
		return -1;
	}

	/**
	 * @generated
	 */
	public static boolean canCreateNode(View containerView, int nodeVisualID) {
		String containerModelID = org.admanager.piadladmapping.plugin.diagram.part.PiADLADManagementMetamodelVisualIDRegistry
				.getModelID(containerView);
		if (!MappingRootEditPart.MODEL_ID.equals(containerModelID)
				&& !"piadlpat".equals(containerModelID) && !"piadl".equals(containerModelID)) { //$NON-NLS-1$ //$NON-NLS-2$
			return false;
		}
		int containerVisualID;
		if (MappingRootEditPart.MODEL_ID.equals(containerModelID)) {
			containerVisualID = org.admanager.piadladmapping.plugin.diagram.part.PiADLADManagementMetamodelVisualIDRegistry
					.getVisualID(containerView);
		} else {
			if (containerView instanceof Diagram) {
				containerVisualID = MappingRootEditPart.VISUAL_ID;
			} else {
				return false;
			}
		}
		switch (containerVisualID) {
		case MappingRootEditPart.VISUAL_ID:
			if (ComponentPortMappingEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (ConnectorRoleMappingEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (ConnectorMappingEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (ComponentMappingEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (CBAPatternEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (ArchitectureEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case CBAPatternEditPart.VISUAL_ID:
			if (CBAPatternNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (CBAPatternCBAPatternCompartmentEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case ArchitectureEditPart.VISUAL_ID:
			if (ArchitectureNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (ArchitectureArchitectureCompartmentEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PRoleEditPart.VISUAL_ID:
			if (PRoleNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PRolePRoleCompartmentEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PConstraintEditPart.VISUAL_ID:
			if (PConstraintNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PComponentEditPart.VISUAL_ID:
			if (PComponentNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PComponentPComponentCompartmentEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PComponent2EditPart.VISUAL_ID:
			if (PComponentName2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PComponentPComponentCompartment2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PConnectorEditPart.VISUAL_ID:
			if (PConnectorNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PConnectorPConnectorCompartmentEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PConnector2EditPart.VISUAL_ID:
			if (PConnectorName2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PConnectorPConnectorCompartment2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case ComponentEditPart.VISUAL_ID:
			if (ComponentNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (ComponentComponentCompartmentEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case Architecture2EditPart.VISUAL_ID:
			if (ArchitectureName2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (ArchitectureArchitectureCompartment2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case ConnectorEditPart.VISUAL_ID:
			if (ConnectorNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (ConnectorConnectorCompartmentEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case CBAPatternCBAPatternCompartmentEditPart.VISUAL_ID:
			if (PMultiplicityEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PRoleEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PComponentPortEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PConnectorRoleEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PComponentEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PConnector2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PRolePRoleCompartmentEditPart.VISUAL_ID:
			if (PConstraintEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PComponentPComponentCompartmentEditPart.VISUAL_ID:
			if (PComponent2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PComponentPort2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PConnectorEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PComponentPComponentCompartment2EditPart.VISUAL_ID:
			if (PComponent2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PComponentPort2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PConnectorEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PConnectorPConnectorCompartmentEditPart.VISUAL_ID:
			if (PConnectorEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PConnectorRole2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PComponent2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PConnectorPConnectorCompartment2EditPart.VISUAL_ID:
			if (PConnectorEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PConnectorRole2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PComponent2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case ArchitectureArchitectureCompartmentEditPart.VISUAL_ID:
			if (ComponentEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (ConnectorEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case ComponentComponentCompartmentEditPart.VISUAL_ID:
			if (PortEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (Architecture2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case ArchitectureArchitectureCompartment2EditPart.VISUAL_ID:
			if (ComponentEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (ConnectorEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case ConnectorConnectorCompartmentEditPart.VISUAL_ID:
			if (Architecture2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (Port2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		}
		return false;
	}

	/**
	 * @generated
	 */
	public static int getLinkWithClassVisualID(EObject domainElement) {
		if (domainElement == null) {
			return -1;
		}
		if (PiadladmanagementPackage.eINSTANCE.getUnification().isSuperTypeOf(
				domainElement.eClass())) {
			return UnificationEditPart.VISUAL_ID;
		}
		if (PiadladmanagementPackage.eINSTANCE.getRelay().isSuperTypeOf(
				domainElement.eClass())) {
			return RelayEditPart.VISUAL_ID;
		}
		return -1;
	}

	/**
	 * User can change implementation of this method to handle some specific
	 * situations not covered by default logic.
	 * 
	 * @generated
	 */
	private static boolean isDiagram(MappingRoot element) {
		return true;
	}

}
